-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
table: Add option DupKeyCheckLazy
to check duplicated key lazily
#55246
Conversation
Hi @lcwangchao. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/retest |
@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
a93279b
to
b0381d4
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #55246 +/- ##
================================================
+ Coverage 72.8486% 74.1474% +1.2987%
================================================
Files 1570 1573 +3
Lines 439518 443407 +3889
================================================
+ Hits 320183 328775 +8592
+ Misses 99610 94604 -5006
- Partials 19725 20028 +303
Flags with carried forward coverage won't be shown. Click here to find out more.
|
b0381d4
to
efc9de6
Compare
efc9de6
to
bfb479d
Compare
pkg/executor/insert.go
Outdated
// https://github.com/pingcap/tidb/issues/54492#issuecomment-2229941881 | ||
// Though it is still in an insert statement, but it seems some old tests still think it should | ||
// check constraints in place, see test: | ||
// https://github.com/pingcap/tidb/blob/3117d3fae50bbb5dabcde7b9589f92bfbbda5dc6/pkg/executor/test/writetest/write_test.go#L419-L426 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are same corner cases here, just check the test case:
tidb/pkg/executor/test/writetest/write_test.go
Lines 419 to 426 in 3117d3f
tk.MustExec(`set tidb_constraint_check_in_place = 0;`) | |
tk.MustExec("replace into t values (1),(2)") | |
tk.MustExec("begin") | |
err = tk.ExecToErr("update t set i = 2 where i = 1") | |
require.Error(t, err) | |
err = tk.ExecToErr("insert into t values (1) on duplicate key update i = i + 1") | |
require.Error(t, err) | |
tk.MustExec("rollback") |
And some comments:
/retest |
@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/retest |
@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
pkg/executor/insert.go
Outdated
// https://github.com/pingcap/tidb/issues/54492#issuecomment-2229941881 | ||
// Though it is still in an insert statement, but it seems some old tests still think it should | ||
// check constraints in place, see test: | ||
// https://github.com/pingcap/tidb/blob/3117d3fae50bbb5dabcde7b9589f92bfbbda5dc6/pkg/executor/test/writetest/write_test.go#L419-L426 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the tidb_constraint_check_in_place_pessimistic
also be explained here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tidb_constraint_check_in_place_pessimistic
is not considerate yet. It will be handled in another PR to introduce a new option like PessimisticLazyCheckMode
which only works for pessimistic txn and DupKeyCheckMode
is DupKeyCheckLazy
pkg/executor/insert.go
Outdated
@@ -236,14 +237,42 @@ func (e *InsertExec) batchUpdateDupRows(ctx context.Context, newRows [][]types.D | |||
e.stats.Prefetch += time.Since(prefetchStart) | |||
} | |||
|
|||
// If the current row has some conflicts, the operation will be changed to update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to wrap L240-L260 to a txn util function like optimizeDupKeyCheckForNormalInsert
? And duplications from L284 to L297 in update.go could be avoided.
Co-authored-by: cfzjywxk <cfzjywxk@gmail.com>
d67f81b
to
b1140a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -1265,9 +1264,6 @@ type SessionVars struct { | |||
// EnableGlobalIndex indicates whether we could create an global index on a partition table or not. | |||
EnableGlobalIndex bool | |||
|
|||
// PresumeKeyNotExists indicates lazy existence checking is enabled. | |||
PresumeKeyNotExists bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to see the complexity is reduced by removing the unncessary states.
@crazycs520 @ekexium |
/approve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for the optimizer part
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cfzjywxk, easonn7, qw4990 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@lcwangchao: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What problem does this PR solve?
Issue Number: ref #54397
What changed and how does it work?
DupKeyCheckLazy
fortable.DupKeyMode
to check duplicated keys lazily in table operations. After this, the key check mode is determined by outside code and the logic is easier to understand.DupKeyCheckDefault
and addDupKeyCheckInPlace
to replace it.IgnoreError
toUpdateExec
andInsertExec
to indicateINSERT IGNORE ...
orUPDATE IGNORE ...
. The conditione.IgnoreError
will replaceec.ErrGroupLevel(errctx.ErrGroupDupKey) != errctx.LevelError
which makes code more readable.LazyCheckKeyNotExists
because the lazy check mode is determined by each scene now, this method is useless now. This PR also removedPresumeKeyNotExists
inSessionVars
.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.